package com.yinshu.teleshield.config; ///*

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * mybatis-plus配置
 *
 * @author yangjunxiong
 * Created on 2021/11/1 10:09
 */
@Slf4j
@Configuration
@MapperScan("com.yinshu.teleshield.mapper")
public class MybatisPlusConfig {


    /**
     * 【 配置master数据库sql方言 】
     *
     * @author yangjunxiong
     * @date 2021/11/3 12:03
     **/
    @Value("${spring.datasource.dynamic.datasource.master.driverClassName:mysql}")
    public String driverClassName;

    /**
     * 分页插件
     */
    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        if (StringUtils.contains(driverClassName, DbType.MYSQL.getDb())) {
            interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
        } else if (StringUtils.contains(driverClassName, DbType.POSTGRE_SQL.getDb())) {
            interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.POSTGRE_SQL));
        }
        return interceptor;
    }

}
